package com.pay.game.central.system.mapper;

import com.github.pagehelper.Page;
import com.pay.game.central.system.bean.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper {

    @Select("select sys_role.* from sys_role,sys_role_user " +
            "where sys_role_user.user_id=#{id,jdbcType=INTEGER} " +
            "and sys_role.id=sys_role_user.role_id")
    List<Role> findRoleByUserId(@Param("id") String id);

    @Select("select * from sys_role where name=#{name}")
    Role findRoleByName(@Param("name") String name);

    @Select("<script> " +
            "   select *  from  sys_role where 1=1 " +
            "   <if test=\"name!=null and name!=''\">" +
            "    and name like concat('%',#{name},'%') " +
            "   </if>" +
            "</script>")
    Page<Role> list(@Param("name") String name);

    @Insert("insert into sys_role(id,name,detail) values(#{id},#{name},#{detail})")
    void insertItem(Role role);

    @Delete("delete from sys_role where id=#{id,jdbcType=INTEGER}")
    void deleteOne(@Param("id") int id);

    @Delete("delete from sys_role_user where role_id=#{roleId,jdbcType=INTEGER}")
    void deleteOneFromRoleUserMap(@Param("roleId") int roleId);


}
